package com.bang.itstack.day05;

/**
 * @ClassName: Singleton01
 * @Desc: 懒汉式 double check+ volatile
 * @author: <Bang>
 * @Date: 2021/10/21 19:19
 * @Version: 1.0
 * @Modified By:
 */
public class Singleton03 {


    /**
     * volatile 防止指令重排序
     */
    private static volatile Singleton03 instance;

    public static Singleton03 getInstance() {
        if (null != instance) {
            return instance;
        }
        synchronized (Singleton03.class) {
            if (null == instance) {
                instance = new Singleton03();
            }
        }
        return instance;

    }
}
